﻿<%@ Page Title="Access Permissions" Language="C#" MasterPageFile="~/Site.Master"
    AutoEventWireup="true" CodeBehind="AccessMgmt.aspx.cs" Inherits="TestJQGrid.AccessMgmt" %>

<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title></title>
    <!-- The jQuery UI theme that will be used by the grid -->
    <link rel="stylesheet" type="text/css" media="screen" href="../themes/redmond/jquery-ui-1.8.2.custom.css" />
    <!-- The jQuery UI theme extension jqGrid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="../themes/ui.jqgrid.css" />
    <!-- jQuery runtime minified -->
    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>
    <!-- The localization file we need, English in this case -->
    <script src="../js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
    <!-- The jqGrid client-side javascript -->
    <script src="../js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="../js/trirand/jquery.jqDatePicker.min.js" type="text/javascript"></script>
    <style type="text/css">
        .style3
        {
            width: 927px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table border="1px">
        <tr style="width: 100%;">
            <td align="center" valign="middle" class="style3">
                <asp:Label ID="Label2" runat="server" Text="Permissions Master" Font-Size="Medium"></asp:Label>
            </td>
        </tr>
        <tr style="width: 100%;">
            <td class="style3">
                <trirand:JQGrid runat="server" ID="JQGrid1" DataSourceID="SqlDataSource1" AutoWidth="True"
                    Height="300px" OnRowSelecting="JQGrid1_RowSelecting">
                    <Columns>
                        <trirand:JQGridColumn DataField="UserId" Editable="true" PrimaryKey="True" />
                        <trirand:JQGridColumn DataField="UserName" Editable="true" />
                        <trirand:JQGridColumn DataField="ProductName" Editable="true" PrimaryKey="True" />
                        <trirand:JQGridColumn DataField="AdminAccess" Editable="true" EditType="DropDown"
                            EditorControlID="AccessTypes" />
                        <trirand:JQGridColumn DataField="AgentAccess" Editable="true" EditType="DropDown"
                            EditorControlID="AccessTypes" />
                        <trirand:JQGridColumn DataField="RulesAccess" Editable="true" EditType="DropDown"
                            EditorControlID="AccessTypes" />
                        <trirand:JQGridColumn DataField="DataAccess" Editable="true" EditType="DropDown"
                            EditorControlID="AccessTypes" />
                        <trirand:JQGridColumn DataField="ReportsAccess" Editable="true" EditType="DropDown"
                            EditorControlID="AccessTypes" />
                        <trirand:JQGridColumn DataField="Status" Editable="true" EditType="DropDown" EditorControlID="StatusValues" />
                        <trirand:JQGridColumn DataField="CreatedBy" Editable="false" />
                        <trirand:JQGridColumn DataField="CreatedOn" Editable="false" DataType="System.DateTime"
                            DataFormatString="{0:dd/MM/yyyy}" />
                    </Columns>
                    <EditDialogSettings CloseAfterEditing="True" ReloadAfterSubmit="true" />
                    <AddDialogSettings CloseAfterAdding="true" ReloadAfterSubmit="true" />
                    <SearchDialogSettings MultipleSearch="True" />
                    <ToolBarSettings ShowEditButton="true" ShowRefreshButton="True" ShowAddButton="true"
                        ShowSearchButton="True" ShowViewRowDetailsButton="True" />
                    <SortSettings InitialSortColumn="UserId"></SortSettings>
                    <AppearanceSettings ShowRowNumbers="True" />
                </trirand:JQGrid>
                <asp:SqlDataSource runat="server" ID="AccessTypesDatasource" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="Select Value from ValidValues where TableName='Permissions' and ColumnName='Access' order by Value " />
                <asp:DropDownList runat="server" ID="AccessTypes" DataSourceID="AccessTypesDatasource"
                    DataValueField="value" DataTextField="value" />
                <asp:SqlDataSource runat="server" ID="StatusDataSource" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="Select [Value] from [ValidValues] where [TableName] IN ( select [AdminAccess] from [Permissions] where [UserId] = @loginId and [ProductName] = @ProductName ) and [ColumnName] = 'Status'">
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
                        <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:DropDownList runat="server" ID="StatusValues" DataSourceID="StatusDataSource"
                    DataValueField="Value" DataTextField="Value" />
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="select * from [Permissions] where [ProductName] = @ProductName AND [Status] IN ( Select [Value] from [ValidValues] where [TableName] IN 
        ( select [AdminAccess] from [Permissions] where [UserId] = @loginId and [ProductName] = @ProductName ) and [ColumnName] = 'Visible' )"
                    InsertCommand="INSERT INTO [Permissions] ([UserId], [UserName], [ProductName], [AdminAccess], [AgentAccess], [RulesAccess], [DataAccess], [ReportsAccess], [Status], [CreatedBy], [CreatedOn]) 
            VALUES ( @UserId, @UserName, @ProductName, @AdminAccess, @AgentAccess, @RulesAccess, @DataAccess, @ReportsAccess, @Status, @loginId, getDate() )"
                    UpdateCommand="UPDATE [Permissions] SET [UserName] = @UserName, [AdminAccess] = @AdminAccess, [AgentAccess] = @AgentAccess, [RulesAccess] = @RulesAccess, [DataAccess] = @DataAccess, 
            [ReportsAccess] = @ReportsAccess, [Status] = @Status, [CreatedBy] = @loginId, [CreatedOn] = getDate() WHERE [UserId] = @UserId AND [ProductName] = @ProductName ">
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
                        <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
                    </SelectParameters>
                    <InsertParameters>
                        <asp:Parameter Name="UserId" Type="String" />
                        <asp:Parameter Name="UserName" Type="String" />
                        <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
                        <asp:Parameter Name="AdminAccess" Type="String" />
                        <asp:Parameter Name="AgentAccess" Type="String" />
                        <asp:Parameter Name="RulesAccess" Type="String" />
                        <asp:Parameter Name="DataAccess" Type="String" />
                        <asp:Parameter Name="ReportsAccess" Type="String" />
                        <asp:Parameter Name="Status" Type="String" />
                        <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="UserName" Type="String" />
                        <asp:Parameter Name="AdminAccess" Type="String" />
                        <asp:Parameter Name="AgentAccess" Type="String" />
                        <asp:Parameter Name="RulesAccess" Type="String" />
                        <asp:Parameter Name="DataAccess" Type="String" />
                        <asp:Parameter Name="ReportsAccess" Type="String" />
                        <asp:Parameter Name="Status" Type="String" />
                        <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
                        <asp:Parameter Name="UserId" Type="String" />
                        <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
                    </UpdateParameters>
                </asp:SqlDataSource>
            </td>
        </tr>
    </table>
</asp:Content>
